WPS Office.apk(点击下载) / dkg.java


package defpackage;

import cn.wps.moffice.OfficeApp;
import cn.wps.moffice_eng.R;
import com.google.firebase.perf.FirebasePerformance;
import com.mopub.common.Constants;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.RandomAccessFile;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.net.ssl.HttpsURLConnection;

/* renamed from: dkg  reason: default package */
public final class dkg {
    private static final int[] cvf = {2, 5, 5};

    /* renamed from: dkg$a */
    public interface a {
        void y(long j);

        void z(long j);
    }

    /* JADX WARNING: Removed duplicated region for block: B:12:0x0032 A[SYNTHETIC, Splitter:B:12:0x0032] */
    /* JADX WARNING: Removed duplicated region for block: B:23:0x004d A[SYNTHETIC, Splitter:B:23:0x004d] */
    private static String a(String str, String str2, HashMap<String, String> hashMap) {
        InputStream inputStream;
        Throwable th;
        String str3 = null;
        byte[] bArr = new byte[1024];
        try {
            inputStream = lwd.a("http://cloudservice23.kingsoft-office-service.com/" + str, str2, null, 3000);
            try {
                ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
                while (true) {
                    int read = inputStream.read(bArr);
                    if (read == -1) {
                        break;
                    }
                    byteArrayOutputStream.write(bArr, 0, read);
                }
                byteArrayOutputStream.flush();
                byteArrayOutputStream.close();
                str3 = byteArrayOutputStream.toString();
                if (inputStream != null) {
                    try {
                        inputStream.close();
                    } catch (Exception e) {
                    }
                }
            } catch (Exception e2) {
                e = e2;
                try {
                    e.printStackTrace();
                    if (inputStream != null) {
                        try {
                            inputStream.close();
                        } catch (Exception e3) {
                        }
                    }
                    return str3;
                } catch (Throwable th2) {
                    th = th2;
                    if (inputStream != null) {
                        try {
                            inputStream.close();
                        } catch (Exception e4) {
                        }
                    }
                    throw th;
                }
            }
        } catch (Exception e5) {
            e = e5;
            inputStream = null;
            e.printStackTrace();
            if (inputStream != null) {
            }
            return str3;
        } catch (Throwable th3) {
            inputStream = null;
            th = th3;
            if (inputStream != null) {
            }
            throw th;
        }
        return str3;
    }

    /* JADX WARNING: Code restructure failed: missing block: B:106:0x01db, code lost:
        r5 = move-exception;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:107:0x01dc, code lost:
        r5 = r4;
        r4 = r5;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:117:0x01f9, code lost:
        r5 = r4;
        r6 = r7;
        r7 = r10;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:126:0x0214, code lost:
        r5 = r7;
        r7 = r10;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:20:0x00b7, code lost:
        r6 = new byte[4096];
     */
    /* JADX WARNING: Code restructure failed: missing block: B:21:0x00bb, code lost:
        r10 = r7.read(r6);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:22:0x00bf, code lost:
        if (r10 <= 0) goto L_0x012a;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:24:0x00c5, code lost:
        if (r21.exists() != false) goto L_0x00ec;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:26:0x00cc, code lost:
        throw new java.io.FileNotFoundException();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:38:0x00ec, code lost:
        r14.write(r6, 0, r10);
        r8 = r8 + ((long) r10);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:39:0x00f5, code lost:
        if (r26 == null) goto L_0x00bb;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:40:0x00f7, code lost:
        r26.y(r8);
     */
    /* JADX WARNING: Code restructure failed: missing block: B:55:0x012a, code lost:
        r6 = false;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:56:0x012b, code lost:
        if (r5 == null) goto L_0x0133;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:58:?, code lost:
        r5.flush();
        r5.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:59:0x0133, code lost:
        if (r7 == null) goto L_0x0138;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:60:0x0135, code lost:
        r7.close();
     */
    /* JADX WARNING: Code restructure failed: missing block: B:61:0x0138, code lost:
        if (r4 != null) goto L_0x013a;
     */
    /* JADX WARNING: Code restructure failed: missing block: B:62:0x013a, code lost:
        r4.disconnect();
        r4 = false;
     */
    /* JADX WARNING: Failed to process nested try/catch */
    /* JADX WARNING: Removed duplicated region for block: B:125:0x0213 A[ExcHandler: FileNotFoundException (e java.io.FileNotFoundException), Splitter:B:8:0x006a] */
    /* JADX WARNING: Removed duplicated region for block: B:136:0x0122 A[SYNTHETIC] */
    /* JADX WARNING: Removed duplicated region for block: B:29:0x00d0 A[SYNTHETIC, Splitter:B:29:0x00d0] */
    /* JADX WARNING: Removed duplicated region for block: B:32:0x00d8 A[Catch:{ IOException -> 0x020a }] */
    /* JADX WARNING: Removed duplicated region for block: B:34:0x00dd A[SYNTHETIC, Splitter:B:34:0x00dd] */
    /* JADX WARNING: Removed duplicated region for block: B:45:0x0104 A[SYNTHETIC, Splitter:B:45:0x0104] */
    /* JADX WARNING: Removed duplicated region for block: B:48:0x0112 A[SYNTHETIC, Splitter:B:48:0x0112] */
    /* JADX WARNING: Removed duplicated region for block: B:51:0x011a A[Catch:{ IOException -> 0x01ee }] */
    /* JADX WARNING: Removed duplicated region for block: B:53:0x011f  */
    /* JADX WARNING: Removed duplicated region for block: B:65:0x0143  */
    /* JADX WARNING: Removed duplicated region for block: B:68:0x014d  */
    /* JADX WARNING: Removed duplicated region for block: B:71:0x015c  */
    /* JADX WARNING: Removed duplicated region for block: B:87:0x01af  */
    /* JADX WARNING: Removed duplicated region for block: B:94:0x01bf A[SYNTHETIC, Splitter:B:94:0x01bf] */
    /* JADX WARNING: Removed duplicated region for block: B:97:0x01c7 A[Catch:{ IOException -> 0x01d3 }] */
    /* JADX WARNING: Removed duplicated region for block: B:99:0x01cc  */
    public static boolean a(String str, File file, long j, long j2, a aVar) throws IOException {
        boolean z;
        HttpURLConnection httpURLConnection;
        OutputStream outputStream;
        InputStream inputStream;
        OutputStream outputStream2;
        String cm = lvo.cm(str);
        StringBuilder sb = new StringBuilder();
        sb.append("id=" + str).append("&signature=" + cm);
        InputStream inputStream2 = null;
        OutputStream outputStream3 = null;
        HttpURLConnection httpURLConnection2 = null;
        RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
        randomAccessFile.seek(j);
        boolean z2 = false;
        int i = 0;
        long j3 = j;
        while (true) {
            if (i >= 3) {
                break;
            }
            try {
                URL url = new URL("http://cloudservice23.kingsoft-office-service.com/download");
                if (url.getProtocol().toLowerCase().equals(Constants.HTTPS)) {
                    lwd.dxN();
                    httpURLConnection = (HttpsURLConnection) url.openConnection();
                    try {
                        ((HttpsURLConnection) httpURLConnection).setHostnameVerifier(lwd.ouv);
                    } catch (FileNotFoundException e) {
                    } catch (IOException e2) {
                        httpURLConnection2 = httpURLConnection;
                        outputStream2 = outputStream3;
                        inputStream = inputStream2;
                        z = true;
                        if (i < 2) {
                        }
                        if (outputStream2 != null) {
                        }
                        if (inputStream != null) {
                        }
                        if (httpURLConnection2 == null) {
                        }
                        i++;
                        inputStream2 = inputStream;
                        outputStream3 = outputStream2;
                        z2 = z;
                    } catch (Throwable th) {
                        httpURLConnection2 = httpURLConnection;
                        th = th;
                        if (outputStream3 != null) {
                        }
                        if (inputStream2 != null) {
                        }
                        if (httpURLConnection2 != null) {
                        }
                        throw th;
                    }
                } else {
                    httpURLConnection = (HttpURLConnection) url.openConnection();
                }
                httpURLConnection.setDoOutput(true);
                httpURLConnection.setRequestMethod(FirebasePerformance.HttpMethod.POST);
                httpURLConnection.setRequestProperty("RANGE", "bytes=" + j3);
                httpURLConnection.setConnectTimeout(15000);
                httpURLConnection.setReadTimeout(15000);
                outputStream = httpURLConnection.getOutputStream();
                try {
                    outputStream.write(sb.toString().getBytes());
                    inputStream = httpURLConnection.getInputStream();
                    if (inputStream != null) {
                        if (aVar == null) {
                            break;
                        }
                        try {
                            aVar.z(j2);
                            break;
                        } catch (FileNotFoundException e3) {
                            if (outputStream != null) {
                                try {
                                    outputStream.flush();
                                    outputStream.close();
                                } catch (IOException e4) {
                                    if (httpURLConnection != null) {
                                    }
                                    lul.b(randomAccessFile);
                                    return false;
                                }
                            }
                            if (inputStream != null) {
                                inputStream.close();
                            }
                            if (httpURLConnection != null) {
                                try {
                                    httpURLConnection.disconnect();
                                } catch (Throwable th2) {
                                    lul.b(randomAccessFile);
                                    throw th2;
                                }
                            }
                            lul.b(randomAccessFile);
                            return false;
                        } catch (IOException e5) {
                            outputStream2 = outputStream;
                            httpURLConnection2 = httpURLConnection;
                            z = true;
                            if (i < 2) {
                                try {
                                    Thread.sleep((long) (cvf[i] * 1000));
                                } catch (InterruptedException e6) {
                                    if (outputStream2 != null) {
                                        try {
                                            outputStream2.flush();
                                            outputStream2.close();
                                        } catch (IOException e7) {
                                            if (httpURLConnection2 != null) {
                                            }
                                            lul.b(randomAccessFile);
                                            if (z) {
                                            }
                                            if (z) {
                                            }
                                            if (file.length() != j2) {
                                            }
                                            file.delete();
                                            return false;
                                        }
                                    }
                                    if (inputStream != null) {
                                        inputStream.close();
                                    }
                                    if (httpURLConnection2 != null) {
                                        httpURLConnection2.disconnect();
                                    }
                                } catch (Throwable th3) {
                                    th = th3;
                                    inputStream2 = inputStream;
                                    outputStream3 = outputStream2;
                                    if (outputStream3 != null) {
                                    }
                                    if (inputStream2 != null) {
                                    }
                                    if (httpURLConnection2 != null) {
                                    }
                                    throw th;
                                }
                            }
                            if (outputStream2 != null) {
                                try {
                                    outputStream2.flush();
                                    outputStream2.close();
                                } catch (IOException e8) {
                                    if (httpURLConnection2 == null) {
                                    }
                                    i++;
                                    inputStream2 = inputStream;
                                    outputStream3 = outputStream2;
                                    z2 = z;
                                }
                            }
                            if (inputStream != null) {
                                inputStream.close();
                            }
                            if (httpURLConnection2 == null) {
                                httpURLConnection2.disconnect();
                            }
                            i++;
                            inputStream2 = inputStream;
                            outputStream3 = outputStream2;
                            z2 = z;
                        } catch (Throwable th4) {
                            inputStream2 = inputStream;
                            outputStream3 = outputStream;
                            httpURLConnection2 = httpURLConnection;
                            th = th4;
                            if (outputStream3 != null) {
                                try {
                                    outputStream3.flush();
                                    outputStream3.close();
                                } catch (IOException e9) {
                                    if (httpURLConnection2 != null) {
                                    }
                                    throw th;
                                }
                            }
                            if (inputStream2 != null) {
                                inputStream2.close();
                            }
                            if (httpURLConnection2 != null) {
                                httpURLConnection2.disconnect();
                            }
                            throw th;
                        }
                    } else {
                        if (outputStream != null) {
                            try {
                                outputStream.flush();
                                outputStream.close();
                            } catch (IOException e10) {
                            }
                        }
                        if (inputStream != null) {
                            inputStream.close();
                        }
                        if (httpURLConnection != null) {
                            httpURLConnection.disconnect();
                            outputStream2 = outputStream;
                            httpURLConnection2 = httpURLConnection;
                            z = z2;
                        } else {
                            outputStream2 = outputStream;
                            httpURLConnection2 = httpURLConnection;
                            z = z2;
                        }
                        i++;
                        inputStream2 = inputStream;
                        outputStream3 = outputStream2;
                        z2 = z;
                    }
                } catch (FileNotFoundException e11) {
                    inputStream = inputStream2;
                    if (outputStream != null) {
                    }
                    if (inputStream != null) {
                    }
                    if (httpURLConnection != null) {
                    }
                    lul.b(randomAccessFile);
                    return false;
                } catch (IOException e12) {
                    outputStream2 = outputStream;
                    inputStream = inputStream2;
                    httpURLConnection2 = httpURLConnection;
                    z = true;
                    if (i < 2) {
                    }
                    if (outputStream2 != null) {
                    }
                    if (inputStream != null) {
                    }
                    if (httpURLConnection2 == null) {
                    }
                    i++;
                    inputStream2 = inputStream;
                    outputStream3 = outputStream2;
                    z2 = z;
                } catch (Throwable th5) {
                    outputStream3 = outputStream;
                    httpURLConnection2 = httpURLConnection;
                    th = th5;
                    if (outputStream3 != null) {
                    }
                    if (inputStream2 != null) {
                    }
                    if (httpURLConnection2 != null) {
                    }
                    throw th;
                }
            } catch (FileNotFoundException e13) {
                httpURLConnection = httpURLConnection2;
                outputStream = outputStream3;
                inputStream = inputStream2;
                if (outputStream != null) {
                }
                if (inputStream != null) {
                }
                if (httpURLConnection != null) {
                }
                lul.b(randomAccessFile);
                return false;
            } catch (IOException e14) {
                outputStream2 = outputStream3;
                inputStream = inputStream2;
                z = true;
                if (i < 2) {
                }
                if (outputStream2 != null) {
                }
                if (inputStream != null) {
                }
                if (httpURLConnection2 == null) {
                }
                i++;
                inputStream2 = inputStream;
                outputStream3 = outputStream2;
                z2 = z;
            } catch (Throwable th6) {
                th = th6;
                if (outputStream3 != null) {
                }
                if (inputStream2 != null) {
                }
                if (httpURLConnection2 != null) {
                }
                throw th;
            }
            lul.b(randomAccessFile);
            if (z && file.length() == j2) {
                return true;
            }
            if (z) {
                lve.d("GPFontDownload", "exception");
            }
            if (file.length() != j2) {
                lve.d("GPFontDownload", "file.length() :" + file.length() + " totalSize :" + j2);
            }
            file.delete();
            return false;
        }
        z = z2;
        lul.b(randomAccessFile);
        if (z) {
        }
        if (z) {
        }
        if (file.length() != j2) {
        }
        file.delete();
        return false;
    }

    public static List<dli> aHq() {
        ArrayList arrayList = new ArrayList();
        try {
            dli[] dliArr = (dli[]) lvb.b(a("allFonts", "lang=" + eip.dHN + "&version=" + OfficeApp.arx().getString(R.string.app_version) + "&count=all", null), dli[].class);
            for (int i = 0; i < dliArr.length; i++) {
                h(dliArr[i].dJB);
                h(dliArr[i].dJC);
                h(dliArr[i].fontImgUrls);
                arrayList.add(dliArr[i]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return arrayList;
    }

    private static void h(String[] strArr) {
        if (strArr != null) {
            for (int i = 0; i < strArr.length; i++) {
                strArr[i] = strArr[i].trim();
            }
        }
    }
}